package com.taiyi.renaissancemall.ui.text_webview

import android.net.http.SslError
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.webkit.*
import com.taiyi.renaissancemall.R
import kotlinx.android.synthetic.main.activity_goods_detail.*
import kotlinx.android.synthetic.main.activity_text_web_view.*

class TextWebViewActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_text_web_view)
        urlWebView.settings.run {
            javaScriptEnabled = true
            blockNetworkImage = false
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            urlWebView.settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW;
        }





        urlWebView.webViewClient = (object : WebViewClient() {
            override fun onPageFinished(p0: WebView?, p1: String?) {
                super.onPageFinished(p0, p1)

            }

            override fun shouldOverrideUrlLoading(
                p0: WebView?,
                request: WebResourceRequest?
            ): Boolean {
                //解决android7.0以后版本加载异常问题
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    p0?.loadUrl(request?.getUrl().toString());
                } else {
                    p0?.loadUrl(request?.toString());
                }
                return true
            }


            override fun onReceivedSslError(
                p0: WebView?,
                handler: SslErrorHandler?,
                error: SslError?
            ) {
                handler?.proceed()
            }

        })
        urlWebView.webChromeClient = (object : WebChromeClient() {
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                super.onProgressChanged(view, newProgress)
                Log.i("sssssss", "----$newProgress")
            }
        })
        var url = intent.getStringExtra("url")
        urlWebView.loadUrl(url)
    }
}
